class Solution
{
public:
    string reverseStr(string s, int k)
    {
        int count = s.size() / (2 * k);
        for (int i = 0; i < count; ++i)
        {
            reverse(s.begin() + 2 * i * k, s.begin() + (2 * i + 1) * k);
        }
        if (s.size() % (2 * k) > 0 && s.size() % (2 * k) <= k)
        {
            reverse(s.begin() + 2 * count * k, s.end());
        }
        else if (s.size() % (2 * k) > k)
        {
            reverse(s.begin() + 2 * count * k, s.begin() + (2 * count + 1) * k);
        }
        return s;
    }
};